//
//  JlUserManager.m
//  JiuLe
//
//  Created by xcq on 15/11/1.
//  Copyright © 2015年 Fine. All rights reserved.
//

#import "JlUserManager.h"
#import "ConfigDefine.h"
#import <objc/runtime.h>
#define kUserManager @"userManager"
static JlUserManager *_jlUserManager = nil;

@implementation JlUserManager


//TODO:在更新资料后请把对象存到本地刷新
+ (instancetype)shareInstance {
    static dispatch_once_t oneToken;
    dispatch_once(&oneToken, ^{
          _jlUserManager = [JlUserManager new];
    });
    
    return _jlUserManager;
}

- (UserInfoModel *)userInfo {
    _userInfo = [NSUserDefaults objectUserForKey:UserInfoUserDefault];
    if (!_userInfo) {
        _userInfo = [UserInfoModel new];
    }
    return _userInfo;
}

+ (void)saveManager {
    if (_jlUserManager != nil) {
        [[NSUserDefaults standardUserDefaults] setObject:_jlUserManager
                                                  forKey:kUserManager];
    }
}

+ (BOOL)managerOfDataIsNull {
    if (_jlUserManager.userInfo == nil || _jlUserManager.userInfo.nickName == nil) {
        return YES;
    } else {
        return NO;
    }
}

+ (void)refreshManager {
    [self saveManager];
    _jlUserManager = [[NSUserDefaults standardUserDefaults] objectForKey:kUserManager];
}

- (void)encodeWithCoder:(NSCoder *)aCoder{

}

@end
